package casa.depesos.app.com.adapter;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.common.base.ui.MyRecyclerView;

import casa.depesos.app.com.App;
import casa.depesos.app.com.R;
import casa.depesos.app.com.activity.InfoActivity;

public class PopAdapter extends RecyclerView.Adapter {

    MyRecyclerView recyclerView;
    String str;
    InfoActivity fragment;

    final String[] email = App.getApp().getResources().getStringArray(R.array.emails);

    public PopAdapter(InfoActivity fragment, MyRecyclerView recyclerView, String str) {
        this.recyclerView = recyclerView;
        this.fragment = fragment;
        this.str = str;
    }

    public void update(String str) {
        this.str = str;
        recyclerView.notifyDataSetChanged();
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.pop_item, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ((MyHolder) holder).bind(position);
    }

    @Override
    public int getItemCount() {
        return email.length;
    }

    class MyHolder extends RecyclerView.ViewHolder {

        TextView tv;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            tv = (TextView) itemView;
        }

        void bind(int p) {
            tv.setText(str + email[p]);
            tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    fragment.setEmail(str + email[p]);
                }
            });
        }
    }
}
